package com.etoak.controller;


import com.etoak.common.core.vo.PageVO;
import com.etoak.common.core.vo.ResultVO;
import com.etoak.entity.Dishes;
import com.etoak.service.impl.DishesServiceImpl;
import com.etoak.vo.DishesVO;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author etoak
 * @since 2025-03-04
 */
@RestController
@RequestMapping("/dishes")
public class DishesController {
    @Autowired
    DishesServiceImpl dishesService;

    @PostMapping
    public ResultVO<Object> add(@Validated @RequestBody Dishes dishes){
        dishesService.add(dishes);
        return ResultVO.success();
    }

    /**
     * 分页查询 get /dishes/list
     * @param pageNum
     * @param pageSize
     * @param dishes
     * @return
     */
    @GetMapping("/list")
    public ResultVO<PageVO<DishesVO>> list(
       @RequestParam(required = false,defaultValue = "1") int pageNum,
       @RequestParam(required = false,defaultValue = "10")int pageSize,
       Dishes dishes){
        PageVO<DishesVO> pageVO = dishesService.list(pageNum, pageSize, dishes);
        return ResultVO.success(pageVO);
    }

    /**
     * 更新菜品
     */
    @PutMapping("/{id}")
    public ResultVO<Object> update(@PathVariable int id,@RequestBody Dishes dishes){
        dishesService.update(id,dishes);
        return ResultVO.success();
    }
    @DeleteMapping("/{id}")
    public ResultVO<Object> delete(@PathVariable int id){
        dishesService.delete(id);
        return ResultVO.success();
    }

}


